public class Test {
    public static void drawMap(){//使用多态
        Rect rect = new Rect();
        //        Shape rect = new Rect(); 和上面一样，不过这个更好理解
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        Shape[] shapes = {cycle,rect,cycle,rect,flower};
        for (Shape shape : shapes){
            shape.draw();
        }
    }
    public static void main(String[] args){
       /* drawMap(new Shape());
        drawMap(new Cycle());
        drawMap(new Rect());
        drawMap(new Flower());*/
        drawMap();
    }
    public static void drawMap2(){//不使用多态的情况
        Rect rect = new Rect();

        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"cycle","rect","cycle","rect","flower"};
        for (String s:shapes){//遍历这个shapes数组
            if (s.equals("cycle")){
                cycle.draw();
            }else if (s.equals("rect")){
                rect.draw();
            }else {
                flower.draw();
            }
        }
    }
}
class Shape{
    public void draw(){
        System.out.println("画图形！");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("画矩形！");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("画圆形！");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("🌹！");
    }
}

